package member;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MailCheckServlet extends HttpServlet
{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
	{
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");

		String memberId=req.getParameter("id");
		String userId=req.getParameter("userId");
		String mailTitle=req.getParameter("mailTitle");
		String mailText=req.getParameter("mailText");
		String type=req.getParameter("type");
		String address=null;

//		mailText=(mailText.trim()==null||mailText.trim()=="")?mailText.trim():mailText;
//		System.out.println(memberId+"\n"+userId+"\n"+mailTitle+"\n"+mailText);
//
//		if(userId==""||mailTitle==""||mailText=="")
//		{
//			userId=null;
//			mailTitle=null;
//			mailText=null;
//		}

		for(int i=0;i<3;i++)
		{
			if(userId==null||mailTitle==null||mailText==null)
			{
				if("rental".equals(type))
				{
					address="/member/userMemberNotReturnMail.jsp";
				}
				else if("reserve".equals(type))
				{
					address="/member/userMemberReserveMail.jsp";
				}
				else
				{
					new IOException().printStackTrace();
				}
				break;
			}
			else
			{
				address="/member/userMemberMailSend.jsp";
			}
		}
		req.setAttribute("type", type);
		req.setAttribute("memberId", memberId);
		req.setAttribute("userId", userId);
		req.setAttribute("mailTitle", mailTitle);
		req.setAttribute("mailText", mailText);

		req.getRequestDispatcher(address).forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
	{
		doGet(req, resp);
	}

}
